package demo2对象比较equals方法;

import java.util.Objects;

public class Person {
    private String name;
    private int age;

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public boolean equals(Object obj) {
       if (obj == null) {
           return false;
       }if (this == obj){
           return true;
        }if (!(obj instanceof Person)){
           return false;
        }

       Person person = (Person)obj;
       return this.name.equals(person.name) && this.age == person.age;
    }

    public int hashCode() {
        return Objects.hash(name, age);
    }

}
